package com.daydr3am.lib;

import com.coe3.data.Information;
import com.daydr3am.thenation.R;
import com.daydr3am.thenation.RootScroll;
import com.daydr3am.thenation.TheNationMain;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TouchyWebView extends WebView {
	public String url;
	Context con;
	boolean isLoaded;

    public TouchyWebView(Context context) {
        super(context);
        con=context;
    }

    public TouchyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        con=context;
    }

    public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        con=context;
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent ev){
        requestDisallowInterceptTouchEvent(false);
        return super.onTouchEvent(ev);
    }
	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev){
		boolean event=super.onInterceptTouchEvent(ev);
		RootScroll main=(RootScroll)((Activity)con).findViewById(R.id.bigscroll);
		main.interupt=!event;
		return event; 
	}
	public void onShowView() {
		// TODO Auto-generated method stub
		if(!isLoaded){
			Log.v("hello", "load url "+url);
			
			Information.logDEBUG("web url: " + url);
			
			this.loadUrl(url);
//			this.loadUrl("http://www.nationmultimedia.com/home/banner/ipad-banner/Nation/Full-Page-Nation/H"+url);
	        requestLayout();
//	    	this.setWebViewClient(new WebViewClient() );  
	        
	        this.setWebViewClient(new WebViewClient(){

	 		    @Override
	 		    public boolean shouldOverrideUrlLoading(WebView view, String url){
	 		    	TheNationMain.ShowDialog_ad(view.getContext(), url);
	 		      return true;
	 		    }
	 		});  
	        
	    	isLoaded=true;
//			
//		    String html = "<html><body>Hello, World!</body></html>"; 
//		    String mime = "text/html";
//		    String encoding = "utf-8";
//
//		    this.getSettings().setJavaScriptEnabled(true);
//		    this.loadDataWithBaseURL(null, html, mime, null, null);
		}
	}          
}